[mlir][NFC] remove-dead-values: Get canonicalization patterns from ops#176712
Merged
matthias-springer merged 1 commit intomainfrom Jan 19, 2026
Merged
Conversation
Member
|
@llvm/pr-subscribers-mlir-core Author: Matthias Springer (matthias-springer) ChangesCollect canonicalization patterns from the region branch ops (instead of populating all canonicalization patterns). Addresses a comment on a merged PR. Full diff: https://github.com/llvm/llvm-project/pull/176712.diff 1 Files Affected:
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index 44b1bcf8e4300..66f369e8a5f65 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -779,13 +779,13 @@ void RemoveDeadValues::runOnOperation() {
module->walk([&](RegionBranchOpInterface regionBranchOp) {
opsToCanonicalize.push_back(regionBranchOp.getOperation());
});
- // TODO: Apply only region branch op canonicalization patterns or find a
- // better API to collect all canonicalization patterns.
+ // Collect all canonicalization patterns for region branch ops.
RewritePatternSet owningPatterns(context);
- for (auto *dialect : context->getLoadedDialects())
- dialect->getCanonicalizationPatterns(owningPatterns);
- for (RegisteredOperationName op : context->getRegisteredOperations())
- op.getCanonicalizationPatterns(owningPatterns, context);
+ DenseSet<RegisteredOperationName> populatedPatterns;
+ for (Operation *op : opsToCanonicalize)
+ if (std::optional<RegisteredOperationName> info = op->getRegisteredInfo())
+ if (populatedPatterns.insert(*info).second)
+ info->getCanonicalizationPatterns(owningPatterns, context);
if (failed(applyOpPatternsGreedily(opsToCanonicalize,
std::move(owningPatterns)))) {
module->emitError("greedy pattern rewrite failed to converge");
|
Member
|
@llvm/pr-subscribers-mlir Author: Matthias Springer (matthias-springer) ChangesCollect canonicalization patterns from the region branch ops (instead of populating all canonicalization patterns). Addresses a comment on a merged PR. Full diff: https://github.com/llvm/llvm-project/pull/176712.diff 1 Files Affected:
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index 44b1bcf8e4300..66f369e8a5f65 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -779,13 +779,13 @@ void RemoveDeadValues::runOnOperation() {
module->walk([&](RegionBranchOpInterface regionBranchOp) {
opsToCanonicalize.push_back(regionBranchOp.getOperation());
});
- // TODO: Apply only region branch op canonicalization patterns or find a
- // better API to collect all canonicalization patterns.
+ // Collect all canonicalization patterns for region branch ops.
RewritePatternSet owningPatterns(context);
- for (auto *dialect : context->getLoadedDialects())
- dialect->getCanonicalizationPatterns(owningPatterns);
- for (RegisteredOperationName op : context->getRegisteredOperations())
- op.getCanonicalizationPatterns(owningPatterns, context);
+ DenseSet<RegisteredOperationName> populatedPatterns;
+ for (Operation *op : opsToCanonicalize)
+ if (std::optional<RegisteredOperationName> info = op->getRegisteredInfo())
+ if (populatedPatterns.insert(*info).second)
+ info->getCanonicalizationPatterns(owningPatterns, context);
if (failed(applyOpPatternsGreedily(opsToCanonicalize,
std::move(owningPatterns)))) {
module->emitError("greedy pattern rewrite failed to converge");
|
joker-eph
approved these changes
Jan 19, 2026
BStott6
pushed a commit
to BStott6/llvm-project
that referenced
this pull request
Jan 22, 2026
…ops (llvm#176712) Collect canonicalization patterns from the region branch ops (instead of populating all canonicalization patterns). Addresses a [comment](llvm#173505 (comment)) on a merged PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Collect canonicalization patterns from the region branch ops (instead of populating all canonicalization patterns).
Addresses a comment on a merged PR.